Skip to content

Properly type purchaseData as Record<string, unknown> #7508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025

Conversation

jnsdls
Copy link
Member

@jnsdls jnsdls commented Jul 2, 2025

Properly Type purchaseData Parameter

This PR improves type safety by changing the type of purchaseData from object to Record<string, unknown> in multiple locations:

  • ConnectButtonProps.ts
  • useSendTransaction.ts

Additionally, it removes unnecessary type casting in PayEmbed.tsx where purchaseData was being cast to Record<string, unknown>.

A changeset has been added to document this patch-level change.

Summary by CodeRabbit

  • Refactor
    • Improved type safety for purchase data by refining its type definition across multiple features.
    • Simplified user interface components by removing redundant type assertions related to purchase data.

PR-Codex overview

This PR focuses on improving type safety by replacing instances of Record<string, unknown> and object with the new type PurchaseData across various files.

Detailed summary

  • Added PurchaseData type in types.ts.
  • Replaced purchaseData?: Record<string, unknown> with purchaseData?: PurchaseData in multiple components and types.
  • Updated relevant files to ensure consistent use of PurchaseData.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Jul 2, 2025

🦋 Changeset detected

Latest commit: 81647bb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jul 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 5:56pm
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 5:56pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 5:56pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 5:56pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2025 5:56pm

Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

## Walkthrough

The changes update the typing of the `purchaseData` property from generic `object` or `unknown` types to a specific `PurchaseData` type (defined as `Record<string, unknown>`) across multiple packages and modules. Redundant type assertions for `purchaseData` were removed in UI components. A changeset documents the patch-level update for the "thirdweb" package reflecting these typing improvements.

## Changes

| File(s)                                                                                                  | Change Summary                                                                                                           |
|---------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| .changeset/orange-files-admire.md                                                                       | Added a changeset file describing a patch update for improved typing of `purchaseData`.                                  |
| packages/thirdweb/src/pay/types.ts                                                                       | Added new type alias `PurchaseData = Record<string, unknown>`.                                                           |
| packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts                                  | Changed `PayUIOptions.purchaseData` type from `object` to `PurchaseData`.                                                |
| packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts                                 | Changed `SendTransactionPayModalConfig.purchaseData` type from `object` to `PurchaseData`.                                |
| packages/thirdweb/src/react/web/ui/PayEmbed.tsx                                                         | Removed explicit type assertions casting `purchaseData` when passing to `BuyWidget`, `CheckoutWidget`, and `TransactionWidget`. |
| packages/thirdweb/src/bridge/Buy.ts                                                                      | Changed `purchaseData` type in `prepare.Options` and `prepare.Result.intent` from `unknown` to `PurchaseData`.           |
| packages/thirdweb/src/bridge/Onramp.ts                                                                   | Changed `purchaseData` type in `OnrampIntent`, `OnrampApiRequestBody`, and `prepare.Options` from `unknown` to `PurchaseData`. |
| packages/thirdweb/src/bridge/OnrampStatus.ts                                                             | Changed `purchaseData` type in `status.Result` union variants from `unknown` to `PurchaseData`.                          |
| packages/thirdweb/src/bridge/Sell.ts                                                                      | Changed `purchaseData` type in `prepare.Options` and `prepare.Result.intent` from `unknown` to `PurchaseData`.           |
| packages/thirdweb/src/bridge/Transfer.ts                                                                  | Changed `purchaseData` type in `prepare.Options` and `prepare.Result["intent"]` from `unknown` to `PurchaseData`.        |
| packages/thirdweb/src/bridge/types/Status.ts                                                             | Changed `purchaseData` type in `Status` union variants from `unknown` to `PurchaseData`.                                 |
| packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts                                                     | Changed `GetBuyWithCryptoQuoteParams.purchaseData` type from `object` to `PurchaseData`.                                 |
| packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts                                                    | Changed `BuyWithCryptoStatus.purchaseData` type from `object` to `PurchaseData`; updated related function parameter types. |
| packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts                                                  | Changed `GetBuyWithCryptoTransferParams.purchaseData` type from `object` to `PurchaseData`.                              |
| packages/thirdweb/src/pay/buyWithFiat/getQuote.ts                                                      | Changed `GetBuyWithFiatQuoteParams.purchaseData` type from `object` to `PurchaseData`.                                   |
| packages/thirdweb/src/pay/buyWithFiat/getStatus.ts                                                     | Changed `BuyWithFiatStatus.purchaseData` type from `object` to `PurchaseData`; updated related function parameter types.  |
| packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx                                                 | Changed `BuyWidgetProps.purchaseData` type from `Record<string, unknown>` to `PurchaseData`.                             |
| packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx                                            | Changed `CheckoutWidgetProps.purchaseData` type from `Record<string, unknown>` to `PurchaseData`.                        |
| packages/thirdweb/src/react/web/ui/Bridge/QuoteLoader.tsx                                              | Changed `QuoteLoaderProps.purchaseData` and `getBridgeParams` parameter type from `object` to `PurchaseData`.            |
| packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx                                        | Changed `TransactionWidgetProps.purchaseData` type from `Record<string, unknown>` to `PurchaseData`.                     |
| packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx                                       | Changed `BridgeOrchestratorProps.purchaseData` from required `object | undefined` to optional `PurchaseData`.             |

## Possibly related PRs

- thirdweb-dev/js#7507: Refined `purchaseData` typing and previously introduced passing `purchaseData` as a prop to payment components.
- thirdweb-dev/js#7202: Addresses `purchaseData` handling in `getBuyWithCryptoTransfer`, related to transfer process and type safety.
- thirdweb-dev/js#7354: Introduced new payment-related widgets whose props include `purchaseData`; this PR updates their typings.

## Suggested reviewers

- 0xFirekeeper

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 610f4f4 and 81647bb.

📒 Files selected for processing (21)
  • .changeset/orange-files-admire.md (1 hunks)
  • packages/thirdweb/src/bridge/Buy.ts (3 hunks)
  • packages/thirdweb/src/bridge/Onramp.ts (4 hunks)
  • packages/thirdweb/src/bridge/OnrampStatus.ts (2 hunks)
  • packages/thirdweb/src/bridge/Sell.ts (3 hunks)
  • packages/thirdweb/src/bridge/Transfer.ts (3 hunks)
  • packages/thirdweb/src/bridge/types/Status.ts (4 hunks)
  • packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts (2 hunks)
  • packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts (7 hunks)
  • packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts (2 hunks)
  • packages/thirdweb/src/pay/buyWithFiat/getQuote.ts (2 hunks)
  • packages/thirdweb/src/pay/buyWithFiat/getStatus.ts (4 hunks)
  • packages/thirdweb/src/pay/types.ts (1 hunks)
  • packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts (2 hunks)
  • packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts (2 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx (2 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx (2 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx (2 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/QuoteLoader.tsx (3 hunks)
  • packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx (2 hunks)
  • packages/thirdweb/src/react/web/ui/PayEmbed.tsx (3 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx
  • packages/thirdweb/src/bridge/Onramp.ts
🚧 Files skipped from review as they are similar to previous changes (19)
  • .changeset/orange-files-admire.md
  • packages/thirdweb/src/pay/types.ts
  • packages/thirdweb/src/pay/buyWithFiat/getQuote.ts
  • packages/thirdweb/src/bridge/OnrampStatus.ts
  • packages/thirdweb/src/react/web/ui/PayEmbed.tsx
  • packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts
  • packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx
  • packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts
  • packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts
  • packages/thirdweb/src/bridge/types/Status.ts
  • packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx
  • packages/thirdweb/src/bridge/Buy.ts
  • packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts
  • packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx
  • packages/thirdweb/src/react/web/ui/Bridge/QuoteLoader.tsx
  • packages/thirdweb/src/bridge/Sell.ts
  • packages/thirdweb/src/bridge/Transfer.ts
  • packages/thirdweb/src/pay/buyWithFiat/getStatus.ts
  • packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Jul 2, 2025
Copy link
Member Author

jnsdls commented Jul 2, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

github-actions bot commented Jul 2, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.11 KB (0%) 1.3 s (0%) 341 ms (+62.97% 🔺) 1.7 s
thirdweb (cjs) 352.76 KB (0%) 7.1 s (0%) 1.6 s (+7.54% 🔺) 8.7 s
thirdweb (minimal + tree-shaking) 5.72 KB (0%) 115 ms (0%) 115 ms (+523.03% 🔺) 229 ms
thirdweb/chains (tree-shaking) 530 B (0%) 11 ms (0%) 18 ms (+211.49% 🔺) 28 ms
thirdweb/react (minimal + tree-shaking) 19.59 KB (0%) 392 ms (0%) 110 ms (+201.65% 🔺) 502 ms

Copy link

codecov bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 51.96%. Comparing base (9c2b0f7) to head (81647bb).

Files with missing lines Patch % Lines
...ckages/thirdweb/src/pay/buyWithCrypto/getStatus.ts 0.00% 4 Missing ⚠️
packages/thirdweb/src/react/web/ui/PayEmbed.tsx 0.00% 3 Missing ⚠️
packages/thirdweb/src/pay/buyWithFiat/getStatus.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7508   +/-   ##
=======================================
  Coverage   51.96%   51.96%           
=======================================
  Files         952      952           
  Lines       64227    64224    -3     
  Branches     4238     4241    +3     
=======================================
  Hits        33377    33377           
+ Misses      30743    30740    -3     
  Partials      107      107           
Flag Coverage Δ
packages 51.96% <0.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
packages/thirdweb/src/bridge/Buy.ts 92.18% <ø> (ø)
packages/thirdweb/src/bridge/Onramp.ts 60.37% <ø> (ø)
packages/thirdweb/src/bridge/OnrampStatus.ts 14.28% <ø> (ø)
packages/thirdweb/src/bridge/Sell.ts 92.96% <ø> (ø)
packages/thirdweb/src/bridge/Transfer.ts 93.15% <ø> (ø)
...ackages/thirdweb/src/pay/buyWithCrypto/getQuote.ts 3.09% <ø> (ø)
...ages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts 4.76% <ø> (ø)
packages/thirdweb/src/pay/buyWithFiat/getQuote.ts 3.89% <ø> (ø)
...react/core/hooks/transaction/useSendTransaction.ts 11.04% <ø> (ø)
...web/src/react/web/ui/Bridge/BridgeOrchestrator.tsx 7.87% <ø> (ø)
... and 7 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jnsdls jnsdls merged commit ca1fb84 into main Jul 2, 2025
24 of 25 checks passed
@jnsdls jnsdls deleted the Properly_type_purchaseData_as_Record_string_unknown_ branch July 2, 2025 18:12
@joaquim-verges joaquim-verges mentioned this pull request Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants